﻿package app.facade
{
	import app.controller.LoadingCommand;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.SharedObject;
	import flash.ui.ContextMenu;
	import flash.utils.Dictionary;
    import org.puremvc.as3.interfaces.IFacade;
    import org.puremvc.as3.patterns.facade.Facade;
    import app.controller.StartupCommand;    	
    import app.controller.AppCommand;    	
	/**
	 * @author hungconcon
	 */
    public class App extends Facade implements IFacade {
        
		/**
		 * Add trivial or another things to below!
		 */
		public static const PUBLIC_STATIC_HERE:String				= "PUBLIC_STATIC_HERE";
        /**
		 * For Loading component
		 */
		public static const LOADING_BUFFERING:String				= "LOADING_BUFFERING";
		public static const LOADING_DONE:String						= "LOADING_DONE";
		public static const LOADING_HIDE:String						= "LOADING_HIDE";
		public static const LOADING_SHOW:String						= "LOADING_SHOW";
		public static const LOADING_ASSET:String					= "LOADING_ASSET";
		public static const LOADING_PERCENT:String					= "LOADING_PERCENT";
		public static const LOADING_PROXY_ALL:String				= "LOADING_PROXY_ALL";
		public static const LOAD_PROXY_DONE:String					= "LOAD_PROXY_DONE";
		
		public static const PROXY_INIT_COMPLETE:String				= "PROXY_INIT_COMPLETE";
		public static const COMPONENT_INIT_COMPLETE:String			= "COMPONENT_INIT_COMPLETE";
		public static const ASSET_LOAD_DONE:String					= "ASSET_LOAD_DONE";
		public static const PREPARE_DATA_UI:String					= "PREPARE_DATA_UI";
		
		/**
		 * The snippets never change!
		 */
		public static const STARTUP:String 						= "STARTUP";
		public static const INIT_DATA:String					= "INIT_DATA";
		public static const INIT_EXTERNAL:String				= "INIT_EXTERNAL";
		public static const INIT_LOAD_DATA_PROXY:String 		= "INIT_LOAD_DATA_PROXY";
		public static const INIT_APPLICATION:String 			= "INIT_APPLICATION";
		public static const INIT_APPLICATION_TEST:String 		= "INIT_APPLICATION_TEST";
		public static const INIT_LOADING:String 				= "INIT_LOADING";
		public static const DATA_LOADED:String					= "DATA_LOADED";				
		public static const SHOW_ERROR:String					= "SHOW_ERROR";
		public static const SHOW_ERROR_DATA_PX:String			= "SHOW_ERROR_DATA_PX";
		public static const DESTROY_APPLICATION:String 			= "DESTROY_APPLICATION";
		public static const SHOW_VERSION:String 				= "SHOW_VERSION";
		public static const HIDE_VERSION:String 				= "HIDE_VERSION";
		
		public static const START_GAME:String 					= "START_GAME";
		public static const FINISH_GAME:String 					= "FINISH_GAME";
			
		public static const SHARE_HIGHT_SCORE_TO_FACEBOOK:String = "SHARE_HIGT_SCORE_TO_FACEBOOK";
		public static const SHOW_BACK_SHADER:String 			= "SHOW_BACK_SHADER";
		public static const HIDE_BACK_SHADER:String 			= "HIDE_BACK_SHADER";
		
		public static const SHOW_SETTING:String 			= "SHOW_SETTING";
		public static const HIDE_SETTING:String 			= "HIDE_SETTING";
		
		public static const CHANGE_MODE:String 				= "CHANGE_MODE";
		/**
		 * Notification in game
		 */

		public static const RIGISTER_TOOLTIP:String				= "RIGISTER_TOOLTIP";
		
		public static const SHOW_LOGO:String 					= "SHOW_LOGO";
		public static const HIDE_LOGO:String 					= "HIDE_LOGO";
		/**
		 * Effect
		 */
		
		public static  const SHOW_EFFECT_BIG_WIN:String			= "SHOW_EFFECT_BIG_WIN";
		public static  const SHOW_EFFECT_WIN:String				= "SHOW_EFFECT_WIN";
		
		/**
		 * Only used for COOKIE!
		 */
		public static var CNAME:String 				= "";
		public static var CSOUNDEFFECT:String 		= "CSE";
		public static var CSOUNDBACKGROUND:String 	= "CSB";
		
        private static var cookie:SharedObject;
		public static function setShared(key:String):void { cookie = SharedObject.getLocal(key,'/');  }
		public static function getCookie(key:String):Object { return cookie.data[key] as Object;  }
		public static function getCookies():Object { return cookie.data as Object;  }
		public static function setCookie(key:String, value:*):void { if(cookie!=null){ cookie.data[key] = value;  saveCookie();   } }
		public static function saveCookie():void { cookie.flush();  }
		
		/**
		 * Only used for INTERNATIONALIZATION or LOCALIZATION!
		 */
		public static var dic:Dictionary;
		public static var LANG:String 		= "vi";
		public static var DATAS:String 		= "Datas";
		
		public static var USERNAME	:String = '';
		public static var CONFIG_LINK:String = '';
		public static var URL:Dictionary = new Dictionary();
		
		public static var USERID:Number = 0;		// user id
		public static var VERSION:Boolean 	= true;
		public static var PROFILER:Boolean 	= true;

		
		public static var deviceSize:Rectangle = new Rectangle();
		public static var MODE:int = 1;
		public static var isPlay:Boolean = false;
		//logic game
		public static var Besauffaktor:Number = 10;
		public static var randomizerKorrektur:Number = 0;
		public static var randomizer:Number = 0;
		public static var schwankfaktor:Number = 1;
		public static var zeit:Number = 0;
		public static var rotationSchwanker:Number = 0;
		public static var stehen:Number = 0;	
		public static var Faktor:Number = 0;	
		
		public static var PTest:String = "";
		
		public static var BANNER_KEY:String = "";
		public static var FACE_ID:String	= "";

		override protected function initializeController() : void {
			super.initializeController();
			registerCommand(STARTUP					, StartupCommand);	
			registerCommand(LOAD_PROXY_DONE			, LoadingCommand);	
			registerCommand(INIT_LOAD_DATA_PROXY	, LoadingCommand);	
			registerCommand(LOADING_PROXY_ALL		, LoadingCommand);	
			
		}
		
		public static function getInstance():App { 
			if ( instance == null ) 
				instance = new App();
			return instance as App; 
		}
        public function startup( stage:Object ):void { 
			sendNotification(App.STARTUP, stage ); 
		}
		
		public static function save(name:String,value:*):void
		{
			 //Get the shared object.
			var so:SharedObject = SharedObject.getLocal("homerun");

			// Update the age variable.
			so.data[name] = value;

			// And flush our changes.
			so.flush();
		}

		public static function load():SharedObject
		{
			// Get the shared object.
			var so:SharedObject = SharedObject.getLocal("homerun");
			return so;
		}
		/**
		 * THE END!
		 */
	
    }
}